﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DullBoard.Data;
using DullBoard.Model;

namespace DullBoard
{
    public partial class frmThread : Form
    {
        private readonly Topic _topic;
        private Thread _thread;

        public frmThread(Topic topic)
        {
            InitializeComponent();

            _topic = topic;

            var repo = new ForumRepository();
            var _thread = repo.GetThread(_topic.Id);

            var top = 0;
            foreach(var post in _thread.Posts)
            {
                var ctl = new ctlPost(post);
                ctl.Load();

                ctl.Left = 0;
                ctl.Width = pnlContent.Width;
                ctl.Top = top;

                pnlContent.Controls.Add(ctl);
        

                top += ctl.Height;
            }

            pnlContent.Height = this.Height - 20;
        }

        private void PnlContentResize(object sender, EventArgs e)
        {
            foreach (var ctl in pnlContent.Controls)
            {
                var post = (ctlPost) ctl;

                if (pnlContent.VerticalScroll.Visible)
                    post.Width = pnlContent.Width - 20;
                else
                    post.Width = pnlContent.Width;
            }
        }
    }
}
